//
//  HYFTabBarController.m
//  MyOCWeibo
//
//  Created by 黄勇锋 on 16/10/3.
//  Copyright © 2016年 黄勇锋. All rights reserved.
//

#import "HYFTabBarController.h"
#import "HYFNavigationController.h"
#import "HYFHomeController.h"
#import "HYFTabBar.h"
#import "HYFDiscoverController.h"
#import "HYFTabBarItem.h"



@interface HYFTabBarController ()<HYFTabBarDelegate>

@end

@implementation HYFTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化 tabbar
    HYFTabBar *tabBar = [[HYFTabBar alloc]init];
    
    tabBar.delegate = self;
    
//    self.tabBar = tabBar; 只读属性用 KVC
    [self setValue:tabBar forKeyPath:@"tabBar"];
    
    //首页
    HYFHomeController *homeVc = [[HYFHomeController alloc]init];
    [self addChildController:homeVc imageName:@"tabbar_home" title:@"首页"];
    //消息
    UITableViewController *megCtrl = [[UITableViewController alloc]init];
    [self addChildController:megCtrl imageName:@"tabbar_message_center" title:@"消息"];
    //发现
    HYFDiscoverController *disCtrl = [[HYFDiscoverController alloc]init];
    [self addChildController:disCtrl imageName:@"tabbar_discover" title:@"发现"];
    //我
    UITableViewController *profileVc = [[UITableViewController alloc]init];
    [self addChildController:profileVc imageName:@"tabbar_profile" title:@"我"];
    
}


- (void)addChildController:(UIViewController *)controller imageName:(NSString *)imgName title:(NSString *)title{
    
    //使用自定义的 tabBarItem 以便遍历 badgeValue 的 subViews
    controller.tabBarItem = [[HYFTabBarItem alloc]init];
    
    controller.tabBarItem.image = [[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imgName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    
    controller.title = title;
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //设置字体
//    dict[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    
    [controller.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    HYFNavigationController *navVc = [[HYFNavigationController alloc]initWithRootViewController:controller];
    
    [self addChildViewController:navVc];
    
}

- (void)tabBar:(HYFTabBar *)tabBar plusButton:(UIButton *)button{
    
    NSLog(@"加号按钮被点击了");
}


@end
